import Vue from 'vue'
import store from '@/common/store'
import {
	RouterMount,
	createRouter
} from 'uni-simple-router';
import {
	BASE_URL
} from '@/env'

//初始化
const router = createRouter({
	platform: process.env.VUE_APP_PLATFORM,
	routerErrorEach: ({
		type,
		msg
	}) => {
		switch (type) {
			case 3: // APP退出应用
				break;
			case 2:
				router.$lockStatus = false;
				break;
			default:
				break;
		}

	},
	routes: ROUTES //路由表
});

//全局路由前置守卫
router.beforeEach((to, from, next) => {
	let userInfo = Boolean(uni.getStorageSync('userInfo'));
	// 权限控制登录
	if (to.meta && to.meta.auth && !userInfo) {
		console.log('%cintercept:暂未登录，路由已拦截:' + to.path, 'color:green;background:yellow');
		store.commit('LOGIN_TIP', true)
	} else {
		next()
	}

})
// 全局路由后置守卫
router.afterEach((to, from) => {})
export {
	router,
	RouterMount
};
